

import java.util.Calendar;
import java.sql.*;
import javax.swing.JOptionPane;

public class Profile {
    public int studentID;
    public boolean onDisplay;
    public String contactInfo;
    public String roommateReq;
    public Calendar bedtime;
    public int neatness;
    public String roomReq;
    public boolean wantDouble;
    public boolean wantTriple;
    public boolean wantQuad;

    private Connection connect;
    
    /*
    public Profile(int studentID, String contactInfo) {
        this.studentID = studentID;
        this.contactInfo = contactInfo;
    }
     * 
     */
    
    public Profile(int studentID, Connection connect){
        this.studentID = studentID;
        this.connect = connect;
        loadFromDB();
    }
    
    //Load object with info from db
    private void loadFromDB(){
        try {
            String loadQuery = "select * from profile where studentID = ?";
            PreparedStatement loadStmt = connect.prepareStatement(loadQuery);
            loadStmt.setInt(1, studentID);
            ResultSet profileInfo = loadStmt.executeQuery();
            if(profileInfo.next()){
                onDisplay = profileInfo.getBoolean("onDisplay");
                contactInfo = profileInfo.getString("contactInfo");
                roommateReq = profileInfo.getString("roommateReq");
                bedtime.setTime(profileInfo.getTime("bedtime"));
                neatness = profileInfo.getInt("neatness");
                roomReq = profileInfo.getString("roomReq");
                wantDouble = profileInfo.getBoolean("wantDouble");
                wantTriple = profileInfo.getBoolean("wantTriple");
                wantQuad = profileInfo.getBoolean("wantQuad");
            }
            
            
        } catch (Exception ex){
            JOptionPane.showMessageDialog(null,
                    "Unable to load student from database.");
            
        }
        
    }
    
    
}
